package com.atguigu.tingshu.order.config;


import com.atguigu.tingshu.common.rabbit.constant.MqConst;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.CustomExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

/**
 * ClassName : CanelOrderMqConfig
 * Package : com.atguigu.tingshu.order.config
 * Description :
 * <p>
 * Author: LHZ
 * Create: 2025/8/4 22:58
 * Version: 1.0
 */
@Configuration
public class CancelOrderMqConfig {
    //创建死信队列
    @Bean
    public Queue cancelQueue(){
        //队列名,是否持久化
        return new Queue(MqConst.QUEUE_CANCEL_ORDER,true);
    }

    //创建死信交换机
    @Bean
    public CustomExchange cancelExchange(){
        Map<String,Object> args = new HashMap<>();
        args.put("x-delayed-type", "direct");
        //交换机名 交换机类型 是否持久化 是否自动删除 交换机参数
        return new CustomExchange(MqConst.EXCHANGE_CANCEL_ORDER,"x-delayed-message",true,false,args);
    }

    @Bean
    public Binding bindingCancel(){
        //绑定队列和交换机
        return BindingBuilder.bind(cancelQueue()).to(cancelExchange())
                //绑定路由key
                .with(MqConst.ROUTING_CANCEL_ORDER)
                //没有额外参数
                .noargs();

    }

}